package com.cskaoyan.service.wxuser;

import com.cskaoyan.bean.po.ohter.MarketGoodsExample;
import com.cskaoyan.bean.po.wxorder.MarketOrder;
import com.cskaoyan.bean.po.wxorder.MarketOrderExample;
import com.cskaoyan.bean.vo.wxuser.UserIndexInfo;
import com.cskaoyan.bean.vo.wxuser.UserIndexVo;
import com.cskaoyan.mapper.MarketOrderGoodsMapper;
import com.cskaoyan.mapper.wxorder.MarketOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Ajun de BBC
 * @Date 2022/7/21 23:18
 * @Version 1.5
 */

@Service
public class WxUserServiceImpl implements WxUserService {


    @Autowired
    MarketOrderMapper marketOrderMapper;
    /**
     *@Description : 个人页面的订单数据显示
     *@Param :
     *@Return :
     */
    @Override
    public UserIndexVo userIndex(Integer userId) {
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        marketOrderExample.createCriteria().andUserIdEqualTo(userId);
        List<MarketOrder> marketOrders = marketOrderMapper.selectByExample(marketOrderExample);
        Integer unrecv = 0;//待收货
        Integer uncomment = 0;//待评价
        Integer unpaid = 0;//待付款
        Integer unship = 0;//待发货
        for (MarketOrder marketOrder : marketOrders) {
            Short orderStatus = marketOrder.getOrderStatus();
            if(orderStatus == 301){
                unrecv++;
            }
            if(orderStatus == 101){
                unpaid++;
            }
            if(orderStatus == 401 || orderStatus == 402){
                uncomment++;
            }
            if(orderStatus == 201){
                unship++;
            }
        }
        UserIndexInfo userIndexInfo = new UserIndexInfo(unrecv, uncomment, unpaid, unship);

        return new UserIndexVo(userIndexInfo);
    }
}
